package cn.autumnorange.app.gateway.busconfig;

import com.netflix.zuul.http.ServletInputStreamWrapper;

import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class BusConfigRequestWrapper extends HttpServletRequestWrapper {
  byte[] data = new byte[0];

  public BusConfigRequestWrapper(HttpServletRequest request) {
    super(request);
  }

  /**
   * unexpected end of stream at
   * okhttp3.internal.http1.Http1Codec$FixedLengthSink.close(Http1Codec.java:307) if
   * (this.bytesRemaining > 0L) { throw new ProtocolException("unexpected end of stream"); }
   *
   * @return
   */
  public int getContentLength() {
    return 0;
  }

  public long getContentLengthLong() {
    return 0l;
  }

  public ServletInputStream getInputStream() throws IOException {
    return new ServletInputStreamWrapper(data);
  }

  public BufferedReader getReader() throws IOException {
    String enc = "UTF-8";
    byte[] data = this.data;
    return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(data), enc));
  }
}
